package com.daodao.daodaoschedule.ui.controller;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author mal
 * @date 2022-11-15 17:02
 */
@RestController
@RequestMapping("/admin")
public class AdminController {

    @RequestMapping("/sayHello")
    public Object sayHello() {

        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        Object details = authentication.getDetails();
        if (details instanceof OAuth2AuthenticationDetails) {
            Map decodedDetails = (Map)((OAuth2AuthenticationDetails) details).getDecodedDetails();
            Integer userId = (Integer) decodedDetails.get("userId");
            System.out.println("---------userId-----"+userId);


        }
        System.out.println("---------"+details.getClass());

        return authentication;
    }
}
